﻿namespace Homework12
{
    internal class Program
    {/// <summary>
     /// 在console里输出当月的日历，如图（本日如彩色表示，不要圆圈，不要农历）
     /// </summary>
     /// <param name="args"></param>
        static void Main(string[] args)
        {
            //清屏
            Console.Clear();
            //改色
            Console.ForegroundColor = ConsoleColor.Red;
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            //输出今天的日期yyyy,MM,dd
            Console.WriteLine(DateTime.Today.ToString("yyyy年MM月dd日"));
            //改回
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;
            //隔线newString('', )
            Console.WriteLine(new String('_', 40));
            //星期标志
            Console.WriteLine("一  二  三  四  五  六  日");
            //获取这个月第一天new DateTime()
            DateTime firstDayOfThisMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            //看看这个月第一天是星期几
            //Console.WriteLine(firstDayOfThisMonth.DayOfWeek);
            //得到日历表格的第一天
            DateTime firstDay=firstDayOfThisMonth.AddDays(1-(int)firstDayOfThisMonth.DayOfWeek);
            //看看这个月最后一天是星期几
            DateTime lastDayOfThisMonth = firstDayOfThisMonth.AddMonths(1).AddDays(-1);
            //Console.WriteLine(lastDayOfThisMonth.DayOfWeek);
            //得到日历最后一天
            DateTime lastDay=lastDayOfThisMonth.AddDays(7-(int)lastDayOfThisMonth.DayOfWeek);
            //开始循环+标出今天
            for (DateTime thisDay=firstDay; thisDay <= lastDay; thisDay=thisDay.AddDays(1))
            {
                if(thisDay.Day<10)
                {
                    Console.Write(" ");
                }
                if((int)thisDay.DayOfWeek!=0)
                {
                    Console.Write(thisDay.Day.ToString(""));
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.Write("  ");
                    if (thisDay == DateTime.Today)
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.BackgroundColor = ConsoleColor.Red;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.BackgroundColor = ConsoleColor.Black;
                    }
                    

                }
                else
                {
                    Console.WriteLine(thisDay.Day.ToString(""));
                }
                if(thisDay==DateTime.Today)
                {
                    Console.ForegroundColor= ConsoleColor.Blue;
                    Console.BackgroundColor = ConsoleColor.Red;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.Black;
                }
                
            }




        }

    }

}